import Packet from "../net/Packet"

// 物品数据
export default class GoodsItem {
	/**
	 * @param id 物品ID
	 * @param num 物品数量
	 */
	public constructor(public id: number, public num: number) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(2010)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): GoodsItem {
		const id = packet.ReadUint()
		const num = packet.ReadUshort()
		return new GoodsItem(id, num)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteUint(this.id)
		packet.WriteUshort(this.num)
		return packet
	}
}
